﻿using System;
using System.Collections.Generic;
using Redmine.Laptop.Common.Constants;
using Redmine.Laptop.Reports.Factories.ReportFactories;
using Redmine.Laptop.Reports.ReportParameters;
using Redmine.Laptop.Reports.Reports;

namespace Redmine.Laptop.Reports.ReportBuilders
{
    public abstract class ReportBuilder
    {
        private readonly IReportFactory _reportFactory;
        
        protected ReportBuilder(IReportFactory reportFactory)
        {
            _reportFactory = reportFactory;
        }

        private static ReportType GetReportType(string report)
        {
            return (ReportType)Enum.Parse(typeof(ReportType), report);
        }

        /// <summary>
        /// Create report
        /// </summary>
        /// <param name="arguments">Input report arguments</param>
        /// <returns></returns>
        public Report CreateReport(Dictionary<string, object> arguments)
        {
            var reportType = GetReportType(arguments[Constant.ArgKeys.Report].ToString());
            var parameters = PrepareParameters(arguments);

            return _reportFactory.Create(reportType, parameters);
        }

        protected abstract Parameters PrepareParameters(Dictionary<string, object> arguments);
    }
}
